// 更新  可进行回复留言
$("#updateStayWordBtn").on("click", function () {
    var stayWordId = $(".stayWordId").val();
    var stayWordState = $(".stayWordState").val();
    var stayWordName = $(".stayWordName").val();
    var stayWordEmail = $(".stayWordEmail").val();
    var stayWordTitle = $(".stayWordTitle").val();
    var stayWordContent = $(".stayWordContent").val();
    var stayWordTime = $(".stayWordTime").val();
    var replyContent = $(".replyContent").val();
    var reg_userEmail = /^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/;
    if (stayWordName != null && stayWordName.length != 0
        && stayWordTitle != null && stayWordTitle.length != 0
        && stayWordContent != null && stayWordContent.length != 0
        && stayWordTime != null && stayWordTime.length != 0) {
        if (stayWordEmail != null && stayWordEmail.length != 0 && reg_userEmail.test(stayWordEmail)) {
            $.ajax({
                type: "POST",
                url: "/stayWordManage/updateStayWord",
                data: {
                    stayWordId: stayWordId,
                    stayWordState: stayWordState,
                    stayWordName: stayWordName,
                    stayWordEmail: stayWordEmail,
                    stayWordTitle: stayWordTitle,
                    stayWordContent: stayWordContent,
                    replyContent: replyContent
                },
                dataType: "json",
                success: function (data) {
                    if (data.result == "success") {
                        alert("更新成功");
                        window.location.reload();
                    }
                },
                error: function () {
                    alert("留言失败");
                }
            });
        } else {
            alert("邮箱格式错误");
        }
    } else {
        alert("留言信息不完整，请不要随意更改");
    }
});

// 查看  可进行更新
function stayWordModalFun(stayWordId) {
    $.ajax({
        type: "GET",
        url: "/stayWordManage/getStayWord?stayWordId=" + stayWordId,
        dataType: "json",
        success: function (data) {
            var stayWord = data.stayWord;
            $(".stayWordId").val(stayWord.stayWordId);
            $(".stayWordState").val(stayWord.stayWordState);
            $(".stayWordName").val(stayWord.stayWordName);
            $(".stayWordEmail").val(stayWord.stayWordEmail);
            $(".stayWordTitle").val(stayWord.stayWordTitle);
            $(".stayWordContent").val(stayWord.stayWordContent);
            $(".stayWordTime").val(stayWord.stayWordTime);
            $(".replyContent").val(stayWord.replyContent);
            $(".replyTime").val(stayWord.replyTime);
            if (stayWord.stayWordState == 1) {
                $(".replyTime-div").hide();
            } else {
                $(".replyTime-div").show();
            }
        },
        error: function () {
            alert("服务器错误，操作失败");
        }
    });
}


// 删除留言
function deleteStayWordModalFun(stayWordId) {
    $("#deleteStayWordBtn").on("click", function () {
        $.ajax({
            type: "GET",
            url: "/stayWordManage/deleteStayWord?stayWordId=" + stayWordId,
            dataType: "json",
            success: function (data) {
                if (data.result == "success") {
                    alert("删除成功");
                    window.location.reload();
                } else {
                    alert("删除失败");
                }
            },
            error: function () {
                alert("服务器错误，操作失败");
            }
        });
    });
}